package com.guc;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 用户servlet 通过HttpServletRequest获取客户端的信息
 */
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doGet");
        //通过request对象获取客户端信息
        String method = req.getMethod();//获取请求方式   get post
        System.out.println(method);
        String remoteHost = req.getRemoteHost();
        System.out.println(remoteHost);
        //获取请求头信息
        String header = req.getHeader("Cookie");
        System.out.println(header);
        // 通过servlet直接 发生请求响应信息
        PrintWriter writer = resp.getWriter();
        writer.println("123454 ai");
        writer.flush();
        writer.close();//流关闭后，会直接向浏览器发出数据
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
